const ajax = {
    get(url, fn) {
        const xhr = new XMLHttpRequest();
        xhr.open('GET', url, true) ;
        xhr.onreadystatechange  = function() {
            if (xhr.readyState === XMLHttpRequest.DONE) {
                fn(xhr.responseText);
            }
        }
        xhr.send();
    },
    post(url, data, fn) {
        const xhr = new XMLHttpRequest();
        xhr.open('POST', url, true);
        if(!data instanceof FormData){
           xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        }
        xhr.onreadystatechange = function () { 
            if (xhr.readyState === XMLHttpRequest.DONE) { 
                fn(xhr.responseText);
            }
        }
        xhr.send(data);
    }
}
 